/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package byblos.negocio.pacote;

import byblos.negocio.NegocioExcecao;
import byblos.util.DataUtil;
import java.io.Serializable;
import java.util.Calendar;
import javax.persistence.Entity;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Temporal;

/**
 *
 * @author Diego
 */
@Entity
@NamedQueries(value = {
    @NamedQuery(name = "PacoteFechadoPorIdioma", query = "SELECT p FROM PacoteFechado p WHERE p.idioma = ?1 AND p.removido = false"),
    @NamedQuery(name = "PacoteFechadoPorIdiomaHome", query = "SELECT p FROM PacoteFechado p WHERE p.visivelHome = true AND  p.idioma = ?1 AND p.removido = false"),
    @NamedQuery(name = "PacoteFechadoPorPeriodo", query = "SELECT p FROM PacoteFechado p WHERE p.removido = false AND " +
    "?1 >= p.checkin AND ?1 < p.checkout OR " +
    "?2 > p.checkin AND ?2 <= p.checkout OR " +
    "?1 < p.checkin AND ?2 > p.checkout")
})
public class PacoteFechado extends Pacote<ItemPacoteFechadoCategoria> implements Serializable {

    @Temporal(javax.persistence.TemporalType.DATE)
    private Calendar checkin;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Calendar checkout;

    public PacoteFechado() {
        super(TipoPacote.FECHADO);
    }

    @Override
    public Calendar getInicio() {
        return getCheckin();
    }

    @Override
    public Calendar getTermino() {
        return getCheckout();
    }

    public Calendar getCheckin() {
        return checkin;
    }

    public int getNumeroNoites() {
        if (checkin == null || checkout == null) {
            throw new NegocioExcecao("As datas de checkin e checkout não foram definidas!");
        }
        return DataUtil.getDiferencaEmDias(checkout, checkin);
    }

    public String getStringCheckin() {
        return DataUtil.toString(checkin);
    }

    public void setCheckin(Calendar checkin) {
        this.checkin = checkin;
    }

    public Calendar getCheckout() {
        return checkout;
    }

    public String getStringCheckout() {
        return DataUtil.toString(checkout);
    }

    public void setCheckout(Calendar checkout) {
        this.checkout = checkout;
    }
}
